package com.weitu.emergency.service.impl;

import com.weitu.emergency.entity.EmergencyVehicle;
import com.weitu.emergency.mapper.EmergencyVehicleMapper;
import com.weitu.emergency.mapper.EmergencyVehicleParameterMapper;
import com.weitu.emergency.service.EmergencyVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-05-10
 */
@Service
public class EmergencyVehicleServiceImpl implements EmergencyVehicleService {

    private final EmergencyVehicleMapper emergencyVehicleMapper;
    private final EmergencyVehicleParameterMapper emergencyVehicleParameterMapper;


    @Autowired
    public EmergencyVehicleServiceImpl(EmergencyVehicleMapper emergencyVehicleMapper, EmergencyVehicleParameterMapper emergencyVehicleParameterMapper) {
        this.emergencyVehicleMapper = emergencyVehicleMapper;
        this.emergencyVehicleParameterMapper = emergencyVehicleParameterMapper;
    }

    @Override
    public List<EmergencyVehicle> findByParam(Map paramMap) {

        return emergencyVehicleMapper.findByParam(paramMap);
    }

    @Override
    public Integer findByParamCount(Map paramMap) {
        return emergencyVehicleMapper.findByParamCount(paramMap);
    }

    @Override
    public EmergencyVehicle findById(String id) {
        EmergencyVehicle emergencyVehicle=emergencyVehicleMapper.findById(id);
        emergencyVehicle.setEmergencyVehicleParameter(emergencyVehicleParameterMapper.findByEmergencyVehicleId(id));
        return emergencyVehicle;
    }

    @Transactional
    @Override
    public Integer add(EmergencyVehicle emergencyVehicle) {
        //添加车辆相关参数
        emergencyVehicleParameterMapper.add(emergencyVehicle.getEmergencyVehicleParameter());
        return emergencyVehicleMapper.add(emergencyVehicle);
    }

    @Transactional
    @Override
    public Integer updateById(EmergencyVehicle emergencyVehicle) {
        //修改车辆相关参数
        emergencyVehicleParameterMapper.updateById(emergencyVehicle.getEmergencyVehicleParameter());
        return emergencyVehicleMapper.updateById(emergencyVehicle);
    }

    @Override
    public Integer deleteById(Map paramMap) {

        return emergencyVehicleMapper.deleteById(paramMap);
    }
}
